<?php
/**
 * @version $Id: country.php 46 2011-09-27 10:42:49Z lnmtrung $
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

class WrdControllerTransaction extends JControllerLegacy 
{
	protected $option;
	protected $controller;
	
	function __construct( $default = array()){
		
		$this->option = 'com_wrd';
		$this->controller = 'transaction';
		
		parent::__construct( $default );
	}

	function display()
	{       
		switch($this->getTask()){
			case 'add':{
				JRequest::setVar( 'hidemainmenu', 1 );
				JRequest::setVar( 'layout', 'form'  );
				JRequest::setVar( 'view'  , 'transaction');
			} 
			break;
			default:
				JRequest::setVar( 'view'  , 'transaction');
				break;
		}
		parent::display();
	}
        
	public function remove(){
		
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		
		$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
		JArrayHelper::toInteger($cid);
		
		if (count( $cid ) < 1) {
			JError::raiseError(500, JText::_( 'Select an item to delete' ) );
		}
		
		$model = $this->getModel('transaction');
		if(!$model->delete($cid)) {
			echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
		}
		
		$this->setRedirect( 'index.php?option='.$this->option.'&controller='.$this->controller,'Removed');
	}
	
	public function cancel(){
	
		$this->setRedirect('index.php?option=com_wrd&controller=transaction');
	}
}